package cn.webestar.scms.user.api.dto.SysConfig;

import cn.webestar.scms.commons.api.SimpleBody;
import cn.webestar.scms.user.entity.SysConfig;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

@Data
@Schema(description = "SysConfigSimpleDTO")
public class SysConfigSimpleDTO extends SimpleBody {

    @Schema(description = "父键")
    private String pcode;

    @Schema(description = "键")
    private String code;

    @Schema(description = "值")
    private String val;

    @Schema(description = "标题")
    private String title;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "创建人")
    private Long creator;

    @Schema(description = "更新人")
    private Long updater;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Override
    public LambdaQueryWrapper<SysConfig> toQueryWapper() {
        LambdaQueryWrapper<SysConfig> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(pcode)) {
            queryWrapper.eq(SysConfig::getPcode, pcode);
        }
        if (StringUtils.hasText(code)) {
            queryWrapper.eq(SysConfig::getCode, code);
        }
        if (StringUtils.hasText(val)) {
            queryWrapper.eq(SysConfig::getVal, val);
        }
        if (StringUtils.hasText(title)) {
            queryWrapper.eq(SysConfig::getTitle, title);
        }
        if (StringUtils.hasText(remark)) {
            queryWrapper.eq(SysConfig::getRemark, remark);
        }
        if (creator!=null) {
            queryWrapper.eq(SysConfig::getCreator, creator);
        }
        if (updater!=null) {
            queryWrapper.eq(SysConfig::getUpdater, updater);
        }
        if (createTime!=null) {
            queryWrapper.eq(SysConfig::getCreateTime, createTime);
        }
        if (updateTime!=null) {
            queryWrapper.eq(SysConfig::getUpdateTime, updateTime);
        }
        return queryWrapper;
    }

}
